package com.im.server.enterprise.cover.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.im.server.enterprise.business.push.DepartmentUserPush;
import com.im.server.enterprise.common.service.DepartmentService;
import com.im.server.general.business.message.data.UserData;
import com.im.server.general.common.message.Head;
import com.im.server.general.common.message.ResultMessage;
import com.im.server.general.common.service.UserService;
import com.im.server.general.common.service.api.UserBaseService;
import com.only.general.annotation.action.ActionMapping;
import com.only.general.annotation.action.MethodMapping;
import com.only.general.annotation.parameter.Define;
import com.only.net.session.SocketSession;

/**
 * 描述：
 * 
 * @author XiaHui
 * @date 2016年1月8日 下午8:12:59
 * @version 0.0.1
 */
@Component
@ActionMapping(value = "1.101")
public class DepartmentUserAction {

	@Resource
	private UserService userService;
	@Resource
	private DepartmentUserPush departmentUserPush;
	@Resource
	private UserBaseService userBaseService;
	@Resource
	private DepartmentService departmentSerivce;
	/**
	 * 发送状态改变
	 * 
	 * @author XiaHui
	 * @date 2017年6月2日 上午11:39:10
	 * @param socketSession
	 * @param head
	 * @param status
	 */
	@MethodMapping(value = "1.1.0008")
	public void sendUserStatus(SocketSession socketSession, Head head, @Define("status") String status) {
		String userId = socketSession.getKey();
		departmentUserPush.pushUserStatus(head.getKey(), userId, status);
		userBaseService.putUserStatus(userId, status);
	}
	
	/**
	 * 用户信息修改后发送给好友（只发id）
	 * 
	 * @author XiaHui
	 * @date 2017年6月2日 上午11:38:23
	 * @param socketSession
	 * @param head
	 */
	@MethodMapping(value = "1.1.0009")
	public void sendUserUpdate(SocketSession socketSession, Head head) {
		String userId = socketSession.getKey();
		departmentUserPush.pushUserUpdate(head, userId);
	}
	
	/**
	 * 获取好友状态
	 * 
	 * @author XiaHui
	 * @date 2017年6月2日 上午11:37:42
	 * @param socketSession
	 * @return
	 */
	@MethodMapping(value = "1.1.0011")
	public ResultMessage getUserDataStatusList(SocketSession socketSession) {
		List<UserData> userDataList = departmentSerivce.getAllUserDataList();
		userService.setUserStatus(userDataList);
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for (UserData userData : userDataList) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("id", userData.getId());
			map.put("status", userData.getStatus());
			list.add(map);
		}
		ResultMessage message = new ResultMessage();
		message.put("list", list);
		return message;
	}
}
